/**
	License:		Artistic license 2.0 (see license.txt, also available online at http://www.perlfoundation.org/artistic_license_2_0)
	Authors:		OrbitalLab (http://www.orbitallab.ru/moonglide/), 2007-2009

	File:			mesh_io.d
	Description:	mesh loading and saving provider
	Date:			3.12.2007 by Digited
*/
module moonglide.resources.io.mesh.MeshIO;

import
	moonglide.resources.io.IResIOProvider,

	moonglide.resources.io.mesh.gms.GMSMeshIO,
	moonglide.resources.io.mesh.trm.TRMMeshIO;


static this()
{
	CMeshIOProvider meshprov = new CMeshIOProvider();

	meshprov._providers[ "gms" ] = new CMeshGMSIOProvider();
	meshprov._providers[ "trm" ] = new CMeshTRMIOProvider();

	CResManager().RegisterProvider( meshprov );
}

//================================================================
/// mesh io provider class
//================================================================
class CMeshIOProvider : IResIOProvider
{
	protected:
		CMeshIOProvider[ char[] ] _providers;		// all providers

	public:
		void Load( char[] extension, ref IResource res, InputStream stream, uint streamsize )
		in
		{
			moonAssert( extension.length > 0, "", __FILE__, __LINE__ );
			moonAssert( stream !is null, "", __FILE__, __LINE__ );
			moonAssert( res !is null, "", __FILE__, __LINE__ );
			moonAssert( streamsize > 0, "", __FILE__, __LINE__ );
		}
		body
		{
			if( extension in _providers )
				_providers[ extension ].Load( extension, res, stream, streamsize );
		}


		bool Save( char[] format, IResource res, ref Array buf ) { return false; }

		void CreateErrorResourceData( IResource res, char[] errorResName )
		{
			// TODO: implement
		}

		char[] GetResourceClass() { return CResMesh.classinfo.name; }
}
